<?php
/**
 * Created by PhpStorm.
 * User: xh
 * Date: 2020/4/22
 * Time: 5:25 PM
 */

namespace app\model\weChat;


use think\Model;

class WeChatLiveLog extends Model
{
    /** 添加
     * @param array $list
     * @param string $identity
     * @return bool
     */
    public function add($list=[],$identity='A'){
        $this->where([['identity','=',$identity],['is_expire','=',0]])->update(['is_expire'=>1,'update_time'=>DateTime(time())]);
        $data = [];
        foreach ($list as $k => $v){
            $data[] = [
                'identity' => $identity,
                'room_name' => $v['name'],
                'room_id' => $v['roomid'],
                'cover_img' => $v['cover_img'],
                'start_time' => $v['start_time'],
                'end_time' => $v['end_time'],
                'anchor_name' => $v['anchor_name'],
                'live_status' => $v['live_status'],
                'share_img' => $v['share_img'],
                'goods_info' => empty($v['goods'])?'':Base64En(JsonEn($v['goods'])),
            ];
        }
        if(!empty($data)){
            $this->insertAll($data);
        }
        return true;
    }
}